<?php
/*
+--------------------------------------------------------------------------
|   AffiliStore 2
|   ========================================
|   Web: http://www.affilistore.com
|   Email: admin (at) affilistore (dot) com
|	License Type: AffiliStore 2 is NOT open source software and limitations apply 
|   Licence Info: Visit AffiliStore website and click on 'Licence'
+--------------------------------------------------------------------------
*/
// Quote variable to make safe
function quote_smart($safevalue)
{
   // Stripslashes
   if (get_magic_quotes_gpc()) {
       $safevalue = stripslashes($safevalue);
   }
   // Quote if not a number or a numeric string
   if (!is_numeric($safevalue)) {
   
		if(version_compare(phpversion(),"4.3.0")=="-1") {
			$safevalue = mysql_escape_string($safevalue);
		} else {
			$safevalue = mysql_real_escape_string($safevalue);
		}
		$safevalue = "'" . $safevalue . "'";
       
   }
   
   return $safevalue;
}
// Quote variable to make safe (no quotes - for search)
function noquote_smart($safevalue)
{
   // Stripslashes
   if (get_magic_quotes_gpc()) {
       $safevalue = stripslashes($safevalue);
   }
   // Quote if not a number or a numeric string
   if (!is_numeric($safevalue)) {
   
		if(version_compare(phpversion(),"4.3.0")=="-1") {
			$safevalue = mysql_escape_string($safevalue);
		} else {
			$safevalue = mysql_real_escape_string($safevalue);
		}
		$safevalue = $safevalue;
       
   }
   
   return $safevalue;
}

// feed function
function productFeed ($sourceFile) {

}



// add product words to page urls
function urltxt($dbnamefield) {

include('fixlist.inc.php');

// get navigation options
$getNavOpt = mysql_query("SELECT * FROM affiliSt_config WHERE name = 'navOptions'");
$navOpt = mysql_fetch_assoc($getNavOpt);
$navOpt = explode(":", $navOpt['value']);
$urlwordcount = $navOpt[9];

$urltxtvar = str_replace($charquotes, "", $dbnamefield);
$urltxtvar = str_replace($andAmps, "", $urltxtvar);
$urltxtvar = str_replace($allCharacters, "", $urltxtvar);
$urltxtvar = str_replace(" ", "-", $urltxtvar);
$urltxtvar = str_replace($multipleminus, "-", $urltxtvar);
		
$pieces = explode("-", $urltxtvar);
$totalurlpieces = count($pieces);
	if ($totalurlpieces < $urlwordcount) {
	$totalwords = $totalurlpieces;
	} else {
	$totalwords = $urlwordcount;
	}
	for ($i = 0; $i < $totalwords; $i++) {
	$theurltxt .= $pieces[$i];
		if ($i != $totalwords-1) {
		$theurltxt .= '-';
		}
	}
return $theurltxt;
}


//mac file size report for admin panel
function ini_get_size($sName)
{
    $sSize = ini_get($sName);
    $sUnit = substr($sSize, -1);
    $iSize = (int) substr($sSize, 0, -1);
    switch (strtoupper($sUnit))
    {
        case 'Y' : $iSize *= 1024; // Yotta
        case 'Z' : $iSize *= 1024; // Zetta
        case 'E' : $iSize *= 1024; // Exa
        case 'P' : $iSize *= 1024; // Peta
        case 'T' : $iSize *= 1024; // Tera
        case 'G' : $iSize *= 1024; // Giga
        case 'M' : $iSize *= 1024; // Mega
        case 'K' : $iSize *= 1024; // kilo
    };
    return $iSize;
}

// unique rand numbers
function randiff($min, $max, $num) {
	if ($min<$max && $max-$min+1 >= $num && $num>0) {
	$random_nums = array();
	$i=0;
		while($i<$num) {
		$rand_num = rand($min, $max);
			if (!in_array($rand_num, $random_nums)) {
			$random_nums[] = $rand_num;
			$i++;
			}
		}
		return $random_nums;
		} else {
		return false;
	}
}

// cache mod
define('CACHE', 'cache');
// Enter the full path to your cache directory
// Ensure it ends with a trailing slash
$cachedir = './cache/';
// More cache settings
$cachetime = 86400; // Seconds to cache files for
$cacheext = 'cache'; // Extension to give cached files (usually cache, htm, txt)
$cachepage = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'].serialize($_GET).serialize($_POST); // Requested page
$cachefile = $cachedir . md5($cachepage) . '.' . $cacheext; // Cache file to either load or create